require(["common", "jQuery", "coAjax", "queryString", "hash_routie"], function(jSouper, $, coAjax, QueryString, hash_routie) {
    var _num = 10;
    var _page = 0;
    var type;

    hash_routie.on("order", function() {
        var queryString = new QueryString(location.hash);
        var _type = queryString.get("type");
        _num = queryString.get("num") || _num;
        _page = queryString.get("page") || _page;
        //状态标识
        if (_type == 2) {
            App.set("title", "未发货订单");
            type = '未发货';
            _page = 0;
            App.set('bus.achs_detail', []);
        } else if (_type == 3) {
            App.set("title", "未付款订单");
            type = '未付款';
            _page = 0;
            App.set('bus.achs_detail', []);
        } else {
            App.set("title", "全部订单");
            type = '全部';
            _page = 0;
            App.set('bus.achs_detail', []);
        }
        _load_achs_page(type, _num, _page);
    });

    function _load_achs_page(type, num, page) {
        App.model.toggle('isloading');
        coAjax.get(appConfig.bus.achs_with_type_and_page_info, {
            type: type,
            num: num,
            page: page
        }, function(result) {
            var info = result.result;
            // console.log("bus.achs_detail", info.achs);
            App.concat("bus.achs_detail", info.achs);
            if (!info.achs.length) {
                App.model.toggle('ismore');
            };
            // page_info = {
            //     total_num: info.total_num,
            //     total_page: info.total_page,
            //     page: info.page,
            //     num: info.num
            // };
            _page += 1;
            // page_info._number_list = [];
            // page_info._number_list.length = info.total_page;
            // App.set("$Cache.bus.achs.page_info", page_info);
            App.model.toggle('isloading');
        }, function(errorCode, xhr, errorMsg) {
            console.log(errorCode);
            alert("error", errorMsg);
        });
    };
    App.set('$Event.get_more_order', function() {
        _load_achs_page(type, _num, _page);
    });
    /*
     * 订单操作的相关事件
     */
    //手机版的 确认收款
    App.set('$Event.setorder_success', function(e, vm) {
        coAjax.put(appConfig.bus["achs_未收货未付款_to_交易完成"] + vm.get("_id"), function(result) {
            alert("success", "交易完成");
            vm.set("info.state", result.result);
        });
    });

});